package com.decompiler.ui;

import java.awt.*;
import javax.swing.border.AbstractBorder;

/**
 * 自定义圆角边框
 */
public class RoundedBorder extends AbstractBorder {
    private Color color;
    private int radius;
    private int thickness;
    private boolean dropShadow;
    private Color shadowColor;
    
    /**
     * 创建一个圆角边框
     * 
     * @param color 边框颜色
     * @param radius 圆角半径
     * @param thickness 边框厚度
     * @param dropShadow 是否添加阴影
     */
    public RoundedBorder(Color color, int radius, int thickness, boolean dropShadow) {
        this.color = color;
        this.radius = radius;
        this.thickness = thickness;
        this.dropShadow = dropShadow;
        this.shadowColor = new Color(0, 0, 0, 50);
    }
    
    /**
     * 创建一个简单的圆角边框
     * 
     * @param color 边框颜色
     * @param radius 圆角半径
     */
    public RoundedBorder(Color color, int radius) {
        this(color, radius, 1, false);
    }
    
    @Override
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        Graphics2D g2d = (Graphics2D) g.create();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        
        // 绘制阴影
        if (dropShadow) {
            g2d.setColor(shadowColor);
            g2d.fillRoundRect(x + 2, y + 2, width - 4, height - 4, radius, radius);
        }
        
        // 绘制边框
        g2d.setColor(color);
        g2d.setStroke(new BasicStroke(thickness));
        g2d.drawRoundRect(x, y, width - 1, height - 1, radius, radius);
        
        g2d.dispose();
    }
    
    @Override
    public Insets getBorderInsets(Component c) {
        int margin = radius / 2;
        return new Insets(margin, margin, margin, margin);
    }
    
    @Override
    public Insets getBorderInsets(Component c, Insets insets) {
        int margin = radius / 2;
        insets.left = insets.right = insets.top = insets.bottom = margin;
        return insets;
    }
    
    @Override
    public boolean isBorderOpaque() {
        return false;
    }
}